/* 
 * File:   MultipleTreeNode.h
 * Author: johnneyshi
 *
 * Created on 2013年3月21日, 上午8:52
 */

#ifndef MULTIPLETREENODE_H
#define	MULTIPLETREENODE_H
#include <list>
#include <iostream>
#include "JInOutPut.h"
#include "JSerialize.h"

using namespace std;

namespace mylib
{
    template <class KeyType>
    class IMultipleTreeNodeCompare
    {
    public:
        virtual bool IsAncestor(const KeyType& _node1,const KeyType& _node2)
        {
            cout << "virtual" << endl;
            return false;
        }
        virtual std::list<KeyType> GenerateAncestor(const KeyType& _key)
        {
            cout << "virtual" << endl;
            std::list<KeyType> keys;
            return keys;
        }
        virtual int Compare(const KeyType& _node1,const KeyType& _node2)
        {
            cout << "virtual" << endl;
            return 0;
        }
        
    };
    
    template <class KeyType,class DataType>
    class MultipleTreeNode : public JSerialize
    {
    public:
        int Serialize(JInOutPut& strea,int& allSize)
        {
            int classSize = 0,selfSize = 0;
            //JSerialize::PutInt(strea,classSize,selfSize);
            JSerialize::SerializeHead(strea,selfSize,classSize);
            ////这里本应该是需要调用这个类的，由于只限于这个系统，并且key是string类型的，所以就直接调用
            JSerialize::Serialize(strea,key,classSize);
            //这里的DataType需要有Serialize方法
            data.Serialize(strea,classSize);
            return JSerialize::SerializeTail(strea,allSize,selfSize,classSize);
        }
	int ReSerialize(JInOutPut& strea)
        {
            int classSize = JSerialize::GetInt(strea,sizeof(int));
            key = JSerialize::ReSerializeString(strea);
            data.ReSerialize(strea);
            return classSize;
        }
        MultipleTreeNode(const KeyType& _key,const DataType& _data,MultipleTreeNode* _pParent):key(_key),data(_data),pParent(_pParent)
        {
            
        }
        MultipleTreeNode():pParent(NULL)
        {
            
        }
        KeyType& GetKey()
        {
            return key;
        }
        //Serialize begin.
        KeyType key;
        DataType data;
        //Serialize end.
        MultipleTreeNode* pParent;
        std::list<MultipleTreeNode*> pChildNodes;
    };
}
#endif	/* MULTIPLETREENODE_H */

